package com.eastseeway.radioproject.calibration;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;

import com.eastseeway.radioproject.R;
import com.eastseeway.radioproject.databinding.ItemCalibrationRvBinding;
import com.eastseeway.radioproject.databinding.ItemEngineerRvBinding;
import com.eastseeway.radioproject.entities.BeanVBus;

public class CalibrationItemAdapter extends ListAdapter<BeanVBus, CalibrationItemAdapter.ItemViewHolder> {

    public CalibrationItemAdapter() {
        super(new DiffUtil.ItemCallback<BeanVBus>() {
            @Override
            public boolean areItemsTheSame(BeanVBus oldItem, BeanVBus newItem) {
                return oldItem.getId().equals(newItem.getId());
            }

            @Override
            public boolean areContentsTheSame(BeanVBus oldItem, BeanVBus newItem) {
                return oldItem.getVoltage().equals(newItem.getVoltage()) && oldItem.getPower() == newItem.getPower();
            }
        });
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemCalibrationRvBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_calibration_rv, parent, false);
        return new ItemViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
        holder.getBinding().setItemBean(getItem(position));
    }


    public static class ItemViewHolder extends RecyclerView.ViewHolder {
        private ItemCalibrationRvBinding binding;

        public ItemViewHolder(ItemCalibrationRvBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        public void setBinding(ItemCalibrationRvBinding binding) {
            this.binding = binding;
        }

        public ItemCalibrationRvBinding getBinding() {
            return this.binding;
        }
    }

}
